<% content_for :navlinks do %>
<%= link_to :back.l, resources_url(:state => @event.state) %>
<% if logged_in_as_manager? %>
|
<%= link_to :edit.l, edit_resource_url(:state => @event.state) %>
<% end %>
<% end %>

<% content_for :external_scripts do -%>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<%= google_maps_key %>"
        type="text/javascript"></script>
<% end %>

<% content_for :scripts do -%>
<% if @event.post_code || @event.address || @event.map_coordinates %>
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.addControl(new GLargeMapControl());
    <% if @event.map_coordinates  =~ /^\s*-?\d+(\.\d*)?,\s*-?\d+(\.\d*)?\s*$/ %>
    var point = new GLatLng(<%= sanitize @event.map_coordinates %>);
    map.setCenter(point, 13);
    var marker = new GMarker(point);
    map.addOverlay(marker);
    <% elsif @event.post_code %>
    var geocoder = new GClientGeocoder();
    geocoder.getLatLng(
        '<%= sanitize((@event.address ? @event.address.gsub(/\r?\n/, ', ') : '') + ', ' + @event.post_code).gsub(/'/, '') %>, United Kingdom',
        function(point) {
          if (point) {
            map.setCenter(point, 13);
            var marker = new GMarker(point);
            map.addOverlay(marker);
          } else {
            geocoder.getLatLng(
                '<%= sanitize(@event.post_code).gsub(/'/, '') %>, United Kingdom',
                function(point) {
                  if (point) {
                    map.setCenter(point, 13);
                    var marker = new GMarker(point);
                    map.addOverlay(marker);
                  }
                }
            );
          }
        }
    );
    <% end -%>
  }
}

$(document).ready(function() {initialize();});
$(document).unload(function() {GUnload();});
<% end %>
<% end %>
<%content_for :title do %><%= h @event.name %><%end%>

<% form_block do %>
  <% fbrow 'event_start_date', :event_start_date.l do %>
  <%= @event.start_date.l(:long) %>
  <% end %>

  <% fbrow 'event_end_date', :event_end_date.l do %>
  <%= @event.end_date.l(:long) %>
  <% end %>

  <% fbrow 'event_required_volunteers', :event_required_volunteers.l do %>
  <%= @event.required_volunteers %>
  <% end %>

  <% fbrow 'event_address', :event_address.l do %>
  <%=simple_format(h @event.address) %>
  <% end %>

  <% fbrow 'event_post_code', :event_post_code.l do %>
  <%=h @event.post_code %>
  <% end %>
  
  <% fbrow 'event_contact', :event_contact.l do %>
  <%=h @event.contact_name %>
  <% if (@event.contact_phone && @event.contact_phone != '') || (@event.contact_email && @event.contact_email != '') %>
  (<%= [@event.contact_phone, @event.contact_email].reject{|i|i.nil? || i == ''}.join(' / ')%>)
  <% end %>
  
  <% end %>
  
  <% if @event.state == 'cfw' %>
  <% fbrow 'availability', :availability.l do %>
  <%= form_tag update_availability_events_url, :class => 'list_form', :id => 'update_availability' %>
    <%= select_tag "attendances[#{@event.id}]", options_for_select(
        [[:attend_first.l, 3], [:attend_second.l, 2], [:attend_maybe.l, 1], [:attend_no.l, 0]],
      current_user.can_attend?(@event) || 0) %>
      <%= submit_tag :update_availability.l %>
      <%= hidden_field_tag 'return_event', @event.id %>
  </p>
  </form>
  <% end %>
  <% end %>


<% end %>
<div class="clearing">&nbsp;</div>

<h3><%= :event_description.l %></h3>
<p id="description"><%= h @event.description %></p>

<div id="map_canvas" style="height: 420px; width: 580px; margin: 1em 6px;"></div>

<div class="clearing">&nbsp;</div>

<% if logged_in_as_manager? or @event.state == 'assigned' %>
<h3><%= :people.l %></h3>

<%
  if logged_in_as_manager?
    conditions = nil
  else
    desired_state = @event.state == 'assigned' ? 'assigned' : 'cfw'
    conditions = ['state=?', desired_state]
  end
%>
  <table class="list">
    <thead>
      <tr>
        <th><%= :name.l %></th>
        <th><%= :profile_field_mobile_phone.l %></th>
        <% if logged_in_as_manager? %>
        <th><%= :assigned_th.l %></th>
        <th><%= :also_assigned_to.l %></th>
        <th>&nbsp;</th>
        <% end %>
      </tr>
    </thead>
    <tbody>
      <% @users = User.find(:all, :include => [:availabilities, :attendances], :conditions => ['availabilities.event_id=? or attendances.event_id=?', @event.id, @event.id]).each do |user| %>
      <tr>
        <td><%=h render_user(user) %></td>
        <td><%=h user.mobile_phone %></td>
        <% if logged_in_as_manager? %>
        <td><%= user.is_assigned_to?(@event) ? :yes.l : :no.l %></td>
        <td><%= user.attendances.find_all{|i|i.event_id!=@event.id}.map{|i|i.event.name}.join(', ') %></td>
        <td><% if user.is_assigned_to? @event %>
          (<%= link_to :deassign.l, deassign_resource_url(@event, :user_id => user.id) %>)
          <% else %>
          (<%= link_to :assign.l, assign_resource_url(@event, :user_id => user.id) %>)
          <% end %>
        </td>
        <% end %>
      </tr>
      <% end %>
    </tbody>
  </table>
<% end %>

<%= render_component :controller => 'comments', :action => 'index', :params => {:event_id => @event.id}, :locals => {:event => @event} %>

<% content_for :scripts do -%>
var noticeRaised = false;
$(document).ready(function() {
  $("select").change(
    function() {
      if (!noticeRaised) {
        if ($("#notice").size() == 0) {
          $("#navlinks").after("<p id=\"notice\"></p>");
        }
        $("#notice").text('<%= :taint_warning_below.l %>');
        noticeRaised = true;
      }
    }
  );
});
<% end %>